package com.lagou.rocketmq.service.impl;

import com.lagou.rocketmq.dao.ProductRepository;
import com.lagou.rocketmq.entity.Product;
import com.lagou.rocketmq.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductRepository productRepository;

    @Override
    public Product findOne(Integer productId) {
        Product product = productRepository.selectById(productId);
        return product;
    }

    @Override
    public void save(Product product) {
        Date date = new Date();
        product.setCreateTime(date);
        product.setUpdateTime(date);
        productRepository.insert(product);
    }

    @Override
    public void update(Product product) {
        productRepository.updateById(product);
    }
}
